﻿using iTool.PluginCore;
using System;
using static Plugin.MessageProvider.SMSService;

namespace Plugin.MessageProvider
{
    public class SMS : ILServerPlugin
    {
        public string Name { get; }

        public SMS()
        {
            this.Name = "SMSProvider";
        }

        // this.SMSProvider.Send("",1)

        [ExportMethod("Send")]
        public MethodResult<string> Send(string toPhone, int enums)
        {
            try
            {
                int smscode = new Random().Next(100000, 999999);

                SMSService sms = new SMSService(new SMSParameter
                {
                    toPhone = toPhone,
                    context = smscode.ToString(),
                    sign = "东周信息科技",
                    templateId = enums
                });

                var result = sms.Send();

                if (result.result == 0)
                {
                    return new MethodResult<string> { IsFinished = true, Date = smscode.ToString() };
                }
                else
                {
                    return new MethodResult<string> { IsFinished = false, Discription = result.errMsg };
                }
            }
            catch (Exception e)
            {

                return new MethodResult<string> { IsFinished = false, Discription = e.Message };
            }
        }
    }
}
